<?php

namespace App\Admin\Controllers;

use App\Models\Poster;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Controllers\AdminController;

class PostersController extends AdminController
{
    protected $title = '海报管理';

    protected function grid()
    {
        $grid = new Grid(new Poster());

        $grid->column('id', 'ID');
        $grid->column('poster', '海报')->image('', 100, 100);
        $grid->column('brief', '摘要');
        $grid->column('created_at', '创建')->display(function () {
        	return $this->created_at->toDatetimeString();
        });
        
        $grid->disableExport();
        $grid->disableRowSelector();
        
        $this->gridActions($grid);

        return $grid;
    }
    
    protected function gridActions(Grid $grid)
    {
	    $grid->actions(function (Grid\Displayers\Actions $actions) {
	    	$actions->disableView();
	    });
    }
    
    protected function form()
    {
        $form = new Form(new Poster());

        $form->image('poster', '海报')->uniqueName();
        $form->text('brief', '摘要');
        
        $this->formTools($form);
        $this->formFooter($form);

        return $form;
    }
    
    protected function formTools(Form $form)
    {
    	$form->tools(function (Form\Tools $tools) {
		    $tools->disableView();
	    });
    }
    
    protected function formFooter(Form $form)
    {
	    $form->footer(function (Form\Footer $footer) {
		    $footer->disableViewCheck();
		    $footer->disableCreatingCheck();
		    $footer->disableEditingCheck();
	    });
    }
}
